package com.wl.zlmanage.utils;/**
 * Created by Administrator on 2018/4/12.
 */

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @program: fcm-mcp
 * @description: MD5加密验证
 * @author: guohailong
 * @create: 2018-04-12 11:49
 **/
public class MD5Util {
    public static final String CHL_ID = "B10001";
    public static final String CHL_TOKEN = "c50ab6d8b9724468a8527692f38e80ef";

    public static String getSign(String chlId, String uid, long ts, String token){
        //根据pid，chlsign，ts进行MD5加密
        String soourceString = chlId+uid+ts+token;
        return getMD5Hash(soourceString);
    }

    /**
    * @Description: 字符串MD5加密
    * @Param:  源字符串
    * @return:  加密后的字符串
    * @Author: guohailong
    * @Date: 2018/4/12
    */
    public static String getMD5Hash(String source){
        StringBuilder sb = new StringBuilder();
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] result = md5.digest(source.getBytes());
            for (byte b : result) {
                sb.append(String.format("%02X", b)); // 10进制转16进制，X 表示以十六进制形式输出，02 表示不足两位前面补0输出
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

//    public static void main(String[] args){
//        //1523526554078
//        //uid=13677777777&chl_id=B0001&sign=4ED203CF917AEDA0C797CB2E825D1E04&ts=1524472289362
//        long time = System.currentTimeMillis();
//        System.out.println(time);
//        String uid = "A123456";
//        String source = "C10001" + uid + time + "a150d0e2f0f14a19b1123ca1acc069f1";
//        System.out.println(getMD5Hash(source));
//    }
}
